/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import java.beans.Beans;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import jpa.converters.DateConverter;
import jpa.entities.DetalleInforme;
import reportes.Reportes;

/**
 *
 * @author innovapps.co
 */
public class SoldaduraForm extends JPanel {
    String logotipo="/reportes/logoEmpresa.jpg";
    String datoPiedeRey = "";
    float datoCeldas = 0, datoPieDeRey = 0, traccion = 0, fluencia = 0;
    List<Float> datos = new ArrayList<>();
    Principal windows;

    public SoldaduraForm(Principal windows) {
        initComponents();
        if (!Beans.isDesignTime()) {
            entityManager.getTransaction().begin();
        }
        this.windows = windows;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("TraccionJPAPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT i FROM InformeSoldadura i");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        clienteQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Cliente c");
        clienteList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clienteQuery.getResultList();
        mallaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT m FROM Malla m");
        mallaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : mallaQuery.getResultList();
        maquinaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT m FROM Maquina m");
        maquinaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : maquinaQuery.getResultList();
        informeSoldaduraQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT i FROM InformeSoldadura i");
        informeSoldaduraList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : informeSoldaduraQuery.getResultList();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        idInformeSoldaduraLabel = new javax.swing.JLabel();
        clienteIdClienteLabel = new javax.swing.JLabel();
        mallasIdMallasLabel = new javax.swing.JLabel();
        maquinaIdMaquinaLabel = new javax.swing.JLabel();
        cumpleLabel = new javax.swing.JLabel();
        idInformeSoldaduraField = new javax.swing.JTextField();
        jComboBoxCliente = new javax.swing.JComboBox();
        jComboBoxMalla = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel17 = new javax.swing.JLabel();
        fechaProduccionLabel = new javax.swing.JLabel();
        fechaLabel = new javax.swing.JLabel();
        fechaField = new javax.swing.JTextField();
        detailScrollPane = new javax.swing.JScrollPane();
        detailTable = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        idDetalleInformeLabel = new javax.swing.JLabel();
        areaNominalLabel = new javax.swing.JLabel();
        cargaMaxLabel = new javax.swing.JLabel();
        resistenciaLabel = new javax.swing.JLabel();
        formaFallaLabel = new javax.swing.JLabel();
        idDetalleInformeField = new javax.swing.JTextField();
        areaNominalField = new javax.swing.JTextField();
        cargaMaxField = new javax.swing.JTextField();
        resistenciaField = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        cboxPorts = new javax.swing.JComboBox();
        cboxPorts1 = new javax.swing.JComboBox();
        jTextFieldLeerPieDeRey = new javax.swing.JTextField();
        btnConnect = new javax.swing.JButton();
        jButtonDetener = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableCeldasPie = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtLog = new javax.swing.JTextArea();
        jComboBoxFalla = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelPromedioCarga = new javax.swing.JLabel();
        jLabelPromedioResistencia = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabelRequisitoResistencia = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabelDesviacionResistencia = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jButtonImprimir = new javax.swing.JButton();
        jButtonNuevoDetalle = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        newButton = new javax.swing.JButton();
        fechaProducionField = new com.toedter.calendar.JDateChooser();

        FormListener formListener = new FormListener();

        masterTable.setFocusable(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idInformeSoldadura}"));
        columnBinding.setColumnName("Id Informe Soldadura");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${clienteIdCliente}"));
        columnBinding.setColumnName("Cliente");
        columnBinding.setColumnClass(jpa.entities.Cliente.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${mallasIdMallas}"));
        columnBinding.setColumnName("Mallas");
        columnBinding.setColumnClass(jpa.entities.Malla.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${maquinaIdMaquina}"));
        columnBinding.setColumnName("Maquina");
        columnBinding.setColumnClass(jpa.entities.Maquina.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaProduccion}"));
        columnBinding.setColumnName("Fecha Producción");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cumple}"));
        columnBinding.setColumnName("Cumple");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addMouseListener(formListener);
        masterScrollPane.setViewportView(masterTable);

        idInformeSoldaduraLabel.setText("Id Informe Soldadura:");

        clienteIdClienteLabel.setText("Cliente Id Cliente:");

        mallasIdMallasLabel.setText("Mallas Id Mallas:");

        maquinaIdMaquinaLabel.setText("Maquina Id Maquina:");

        cumpleLabel.setText("Cumple:");

        idInformeSoldaduraField.setEditable(false);
        idInformeSoldaduraField.setFocusable(false);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idInformeSoldadura}"), idInformeSoldaduraField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clienteList, jComboBoxCliente, "");
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.clienteIdCliente}"), jComboBoxCliente, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, mallaList, jComboBoxMalla);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.mallasIdMallas}"), jComboBoxMalla, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, maquinaList, jComboBox1);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.maquinaIdMaquina}"), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jCheckBox1.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.cumple}"), jCheckBox1, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel17.setText("Ensayo Esfuerzo Cortante a la Soldadura");

        fechaProduccionLabel.setText("Fecha Producción:");

        fechaLabel.setText("Fecha:");

        fechaField.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.fecha}"), fechaField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(new DateConverter());
        bindingGroup.addBinding(binding);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.detalleInformeList}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable, "detail");
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${areaNominal}"));
        columnBinding.setColumnName("Area Nominal (mm2)");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cargaMax}"));
        columnBinding.setColumnName("Carga Máxima (Kg)");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${resistencia}"));
        columnBinding.setColumnName("Resistencia (N)");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${formaFalla}"));
        columnBinding.setColumnName("Forma de Falla");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        jTableBinding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        detailScrollPane.setViewportView(detailTable);

        idDetalleInformeLabel.setText("Id Detalle Informe:");

        areaNominalLabel.setText("Area Nominal:");

        cargaMaxLabel.setText("Carga Max:");

        resistenciaLabel.setText("Resistencia:");

        formaFallaLabel.setText("Forma Falla:");

        idDetalleInformeField.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idDetalleInforme}"), idDetalleInformeField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        areaNominalField.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.areaNominal}"), areaNominalField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        cargaMaxField.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.cargaMax}"), cargaMaxField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        resistenciaField.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.resistencia}"), resistenciaField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Herramientas"));
        jPanel3.setMinimumSize(new java.awt.Dimension(484, 64));

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        cboxPorts.setMinimumSize(new java.awt.Dimension(50, 20));
        cboxPorts.setPreferredSize(new java.awt.Dimension(80, 25));
        jToolBar1.add(cboxPorts);

        cboxPorts1.setMinimumSize(new java.awt.Dimension(80, 20));
        cboxPorts1.setPreferredSize(new java.awt.Dimension(80, 25));
        jToolBar1.add(cboxPorts1);

        jTextFieldLeerPieDeRey.setMaximumSize(new java.awt.Dimension(60, 25));
        jTextFieldLeerPieDeRey.setMinimumSize(new java.awt.Dimension(60, 25));
        jTextFieldLeerPieDeRey.setPreferredSize(new java.awt.Dimension(60, 25));
        jTextFieldLeerPieDeRey.addActionListener(formListener);
        jToolBar1.add(jTextFieldLeerPieDeRey);

        btnConnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/play.png"))); // NOI18N
        btnConnect.setToolTipText("Iniciar");
        btnConnect.setMaximumSize(new java.awt.Dimension(39, 45));
        btnConnect.setMinimumSize(new java.awt.Dimension(39, 45));
        btnConnect.addActionListener(formListener);
        jToolBar1.add(btnConnect);

        jButtonDetener.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/stop.png"))); // NOI18N
        jButtonDetener.setToolTipText("Parar");
        jButtonDetener.addActionListener(formListener);
        jToolBar1.add(jButtonDetener);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jTableCeldasPie.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Celdas", "Pie de Rey"
            }
        ));
        jTableCeldasPie.setEnabled(false);
        jTableCeldasPie.setFocusable(false);
        jScrollPane1.setViewportView(jTableCeldasPie);

        txtLog.setEditable(false);
        txtLog.setColumns(20);
        txtLog.setLineWrap(true);
        txtLog.setRows(5);
        txtLog.setFocusable(false);
        jScrollPane2.setViewportView(txtLog);

        jComboBoxFalla.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Punto de Soldadura", "Grafil" }));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.formaFalla}"), jComboBoxFalla, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jPanel2.setLayout(new java.awt.GridLayout(4, 3));
        jPanel2.add(jLabel12);

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("Carga Máxima");
        jPanel2.add(jLabel11);

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Resistencia");
        jPanel2.add(jLabel10);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Promedio:");
        jPanel2.add(jLabel2);

        jLabelPromedioCarga.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel2.add(jLabelPromedioCarga);

        jLabelPromedioResistencia.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel2.add(jLabelPromedioResistencia);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Requisito de Norma:");
        jPanel2.add(jLabel4);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel2.add(jLabel5);

        jLabelRequisitoResistencia.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel2.add(jLabelRequisitoResistencia);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Desviación:");
        jPanel2.add(jLabel6);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel2.add(jLabel8);

        jLabelDesviacionResistencia.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel2.add(jLabelDesviacionResistencia);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 186, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 340, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(idDetalleInformeLabel)
                                    .addComponent(areaNominalLabel)
                                    .addComponent(cargaMaxLabel)
                                    .addComponent(resistenciaLabel)
                                    .addComponent(formaFallaLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(resistenciaField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cargaMaxField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(areaNominalField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(idDetalleInformeField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxFalla, 0, 200, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(idDetalleInformeLabel)
                                    .addComponent(idDetalleInformeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(areaNominalLabel)
                                    .addComponent(areaNominalField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cargaMaxLabel)
                                    .addComponent(cargaMaxField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(resistenciaLabel)
                                    .addComponent(resistenciaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(formaFallaLabel)
                                    .addComponent(jComboBoxFalla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );

        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/print.png"))); // NOI18N
        jButtonImprimir.setFocusable(false);
        jButtonImprimir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonImprimir.setMaximumSize(new java.awt.Dimension(44, 44));
        jButtonImprimir.setMinimumSize(new java.awt.Dimension(44, 44));
        jButtonImprimir.setPreferredSize(new java.awt.Dimension(39, 39));
        jButtonImprimir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonImprimir.addActionListener(formListener);

        jButtonNuevoDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/add_list.png"))); // NOI18N
        jButtonNuevoDetalle.setToolTipText("Agregar Ensayo");
        jButtonNuevoDetalle.addActionListener(formListener);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/save.png"))); // NOI18N
        saveButton.setToolTipText("Guardar");
        saveButton.addActionListener(formListener);

        refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/refresh.png"))); // NOI18N
        refreshButton.setToolTipText("Refrescar");
        refreshButton.addActionListener(formListener);

        newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/new.png"))); // NOI18N
        newButton.setToolTipText("Nuevo");
        newButton.addActionListener(formListener);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(refreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNuevoDetalle, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(refreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonNuevoDetalle, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.fechaProduccion}"), fechaProducionField, org.jdesktop.beansbinding.BeanProperty.create("date"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(idInformeSoldaduraLabel)
                                            .addComponent(clienteIdClienteLabel)
                                            .addComponent(mallasIdMallasLabel)
                                            .addComponent(cumpleLabel)
                                            .addComponent(fechaLabel)
                                            .addComponent(maquinaIdMaquinaLabel)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(fechaProduccionLabel)
                                        .addGap(18, 18, 18)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jCheckBox1)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addComponent(jComboBox1, 0, 250, Short.MAX_VALUE)
                                    .addComponent(jComboBoxMalla, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBoxCliente, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(fechaField)
                                    .addComponent(idInformeSoldaduraField)
                                    .addComponent(fechaProducionField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(detailScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
                            .addComponent(masterScrollPane))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(idInformeSoldaduraLabel)
                            .addComponent(idInformeSoldaduraField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fechaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fechaLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(clienteIdClienteLabel)
                            .addComponent(jComboBoxCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(mallasIdMallasLabel)
                            .addComponent(jComboBoxMalla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(maquinaIdMaquinaLabel)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(fechaProducionField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(fechaProduccionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addComponent(cumpleLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(detailScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(134, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.awt.event.MouseListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == jTextFieldLeerPieDeRey) {
                SoldaduraForm.this.jTextFieldLeerPieDeReyActionPerformed(evt);
            }
            else if (evt.getSource() == btnConnect) {
                SoldaduraForm.this.btnConnectActionPerformed(evt);
            }
            else if (evt.getSource() == jButtonDetener) {
                SoldaduraForm.this.jButtonDetenerActionPerformed(evt);
            }
            else if (evt.getSource() == jButtonImprimir) {
                SoldaduraForm.this.jButtonImprimirActionPerformed(evt);
            }
            else if (evt.getSource() == jButtonNuevoDetalle) {
                SoldaduraForm.this.jButtonNuevoDetalleActionPerformed(evt);
            }
            else if (evt.getSource() == saveButton) {
                SoldaduraForm.this.saveButtonActionPerformed(evt);
            }
            else if (evt.getSource() == refreshButton) {
                SoldaduraForm.this.refreshButtonActionPerformed(evt);
            }
            else if (evt.getSource() == newButton) {
                SoldaduraForm.this.newButtonActionPerformed(evt);
            }
        }

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == masterTable) {
                SoldaduraForm.this.masterTableMouseClicked(evt);
            }
        }

        public void mouseEntered(java.awt.event.MouseEvent evt) {
        }

        public void mouseExited(java.awt.event.MouseEvent evt) {
        }

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
        }
    }// </editor-fold>//GEN-END:initComponents

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        nuevo();
    }//GEN-LAST:event_newButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        guardar();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void jButtonNuevoDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNuevoDetalleActionPerformed
        guardar();
        jTableCeldasPie.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{"Celdas", "Pie de Rey"}));
        datoPiedeRey = "";
        datoCeldas = 0;
        datoPieDeRey = 0;
        traccion = 0;
        fluencia = 0;
        datos = new ArrayList<>();
        int index = masterTable.getSelectedRow();
        jpa.entities.InformeSoldadura i = list.get(masterTable.convertRowIndexToModel(index));
        Collection<jpa.entities.DetalleInforme> ds = i.getDetalleInformeList();
        if (ds == null) {
            ds = new LinkedList<>();
            i.setDetalleInformeList((List) ds);
        }
        jpa.entities.DetalleInforme d = new jpa.entities.DetalleInforme();
        d.setFormaFalla("Punto de Soldadura");
        entityManager.persist(d);
        d.setInformeSoldaduraIdInformeSoldadura(i);
        d.setAreaNominal(i.getMallasIdMallas().getAreaNominal());
        ds.add(d);
        masterTable.clearSelection();
        masterTable.setRowSelectionInterval(index, index);
        int row = ds.size() - 1;
        detailTable.setRowSelectionInterval(row, row);
        detailTable.scrollRectToVisible(detailTable.getCellRect(row, 0, true));
        cboxPorts.setEnabled(true);
        cboxPorts1.setEnabled(true);
        btnConnect.setEnabled(true);
//        actualizar();
    }//GEN-LAST:event_jButtonNuevoDetalleActionPerformed

    private void jTextFieldLeerPieDeReyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldLeerPieDeReyActionPerformed
        DefaultTableModel tableModelTemp = (DefaultTableModel) jTableCeldasPie.getModel();
        Float datoTemp;

        String temp = jTextFieldLeerPieDeRey.getText();
        temp = temp.replace("'", "-");
        try {
            datoTemp = Float.parseFloat(temp);
            if (datoTemp > 0) {
                if (datoTemp == datoPieDeRey) {
                    jTextFieldLeerPieDeRey.setText("");
                    detener();
                } else {
                    datos.add(datoCeldas);
                    Object nuevaFila[] = {datoCeldas, datoTemp};
                    tableModelTemp.addRow(nuevaFila);
                    datoPieDeRey = datoTemp;
                }
            }
        } catch (NumberFormatException ex) {
        }
        jTextFieldLeerPieDeRey.setText("");
    }//GEN-LAST:event_jTextFieldLeerPieDeReyActionPerformed

    private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
//            jComboBoxDiametro.setEnabled(false);
//            longitudField.setEnabled(false);
//            elongacionPorcentajeField.setEnabled(false);
        btnConnect.setEnabled(false);
        cboxPorts.setEnabled(false);
        cboxPorts1.setEnabled(false);
        jButtonDetener.setEnabled(true);
        jTextFieldLeerPieDeRey.setEnabled(true);
        jTextFieldLeerPieDeRey.grabFocus();
        datos = new ArrayList<>();
        windows.communicator.connect((String) cboxPorts.getSelectedItem());
        if (windows.communicator.getConnected() == true) {
            if (windows.communicator.initIOStream() == true) {
                windows.communicator.initListener();
            }
        }
        windows.paralelo.escribirEnPuerto((byte) 1, (String) cboxPorts1.getSelectedItem());

    }//GEN-LAST:event_btnConnectActionPerformed

    private void jButtonDetenerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDetenerActionPerformed
        detener();
    }//GEN-LAST:event_jButtonDetenerActionPerformed

    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
    }//GEN-LAST:event_refreshButtonActionPerformed

    private void masterTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_masterTableMouseClicked
        calcularDatos();
    }//GEN-LAST:event_masterTableMouseClicked

    private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed
        impresion("soldadura.jasper");
    }//GEN-LAST:event_jButtonImprimirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField areaNominalField;
    private javax.swing.JLabel areaNominalLabel;
    public javax.swing.JButton btnConnect;
    private javax.swing.JTextField cargaMaxField;
    private javax.swing.JLabel cargaMaxLabel;
    public javax.swing.JComboBox cboxPorts;
    public javax.swing.JComboBox cboxPorts1;
    private javax.swing.JLabel clienteIdClienteLabel;
    private java.util.List<jpa.entities.Cliente> clienteList;
    private javax.persistence.Query clienteQuery;
    private javax.swing.JLabel cumpleLabel;
    private javax.swing.JScrollPane detailScrollPane;
    private javax.swing.JTable detailTable;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JTextField fechaField;
    private javax.swing.JLabel fechaLabel;
    private javax.swing.JLabel fechaProduccionLabel;
    private com.toedter.calendar.JDateChooser fechaProducionField;
    private javax.swing.JLabel formaFallaLabel;
    private javax.swing.JTextField idDetalleInformeField;
    private javax.swing.JLabel idDetalleInformeLabel;
    private javax.swing.JTextField idInformeSoldaduraField;
    private javax.swing.JLabel idInformeSoldaduraLabel;
    private java.util.List<jpa.entities.InformeSoldadura> informeSoldaduraList;
    private javax.persistence.Query informeSoldaduraQuery;
    private javax.swing.JButton jButtonDetener;
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonNuevoDetalle;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBoxCliente;
    private javax.swing.JComboBox jComboBoxFalla;
    private javax.swing.JComboBox jComboBoxMalla;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelDesviacionResistencia;
    private javax.swing.JLabel jLabelPromedioCarga;
    private javax.swing.JLabel jLabelPromedioResistencia;
    private javax.swing.JLabel jLabelRequisitoResistencia;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableCeldasPie;
    private javax.swing.JTextField jTextFieldLeerPieDeRey;
    private javax.swing.JToolBar jToolBar1;
    private java.util.List<jpa.entities.InformeSoldadura> list;
    private java.util.List<jpa.entities.Malla> mallaList;
    private javax.persistence.Query mallaQuery;
    private javax.swing.JLabel mallasIdMallasLabel;
    private javax.swing.JLabel maquinaIdMaquinaLabel;
    private java.util.List<jpa.entities.Maquina> maquinaList;
    private javax.persistence.Query maquinaQuery;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JButton newButton;
    private javax.persistence.Query query;
    private javax.swing.JButton refreshButton;
    private javax.swing.JTextField resistenciaField;
    private javax.swing.JLabel resistenciaLabel;
    private javax.swing.JButton saveButton;
    public javax.swing.JTextArea txtLog;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void actualizar() {
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
    }

    public void nuevo() {
        jpa.entities.InformeSoldadura i = new jpa.entities.InformeSoldadura();
        entityManager.persist(i);
        i.setFecha(new Date());
        list.add(i);
        int row = list.size() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
        habilitarDetalle(false);
        jComboBoxMalla.setEnabled(true);
    }

    public void setDatoCeldas(String a) {
        try {
            a = a.replace(" ", "");
            datoCeldas = Float.parseFloat(a);
        } catch (NumberFormatException ex) {
            System.err.println(ex.getMessage());
        }
    }

    public void detener() {
        saveButton.setEnabled(true);
        btnConnect.setEnabled(false);
        jComboBoxFalla.setEnabled(true);
        jTextFieldLeerPieDeRey.setEnabled(false);
        jButtonDetener.setEnabled(false);
        windows.paralelo.escribirEnPuerto((byte) 0, (String) cboxPorts1.getSelectedItem());
//        communicator.disconnect();
        windows.paralelo.cerrarPuerto();
        traccion = datos.get(0);
        for (Float celda : datos) {
            if (celda > traccion) {
                traccion = celda;
            }
        }
        cargaMaxField.setText(String.valueOf(traccion));
        resistenciaField.setText(String.valueOf(traccion * 9.80665002864));
        calcularDatos();
    }

    public void habilitarFormulario(boolean habilitar) {
        //Deshabilitar componentes
        jTextFieldLeerPieDeRey.setEnabled(!habilitar);

        newButton.setEnabled(habilitar);
        jButtonDetener.setEnabled(!habilitar);
    }

    public void habilitarDetalle(boolean habilitar) {
        //Deshabilitar componentes
        jTextFieldLeerPieDeRey.setEnabled(habilitar);
        cboxPorts.setEnabled(habilitar);
        cboxPorts1.setEnabled(habilitar);
        btnConnect.setEnabled(habilitar);
        jButtonDetener.setEnabled(habilitar);
        jComboBoxFalla.setEnabled(habilitar);
    }

    public void guardar() {
        try {
            calcularDatos();
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
            calcularDatos();
            jComboBoxMalla.setEnabled(false);
            jComboBoxFalla.setEnabled(false);
            actualizar();
            int row = list.size() - 1;
            masterTable.setRowSelectionInterval(row, row);
            masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
        } catch (RollbackException rex) {
            entityManager.getTransaction().begin();
            List<jpa.entities.InformeSoldadura> merged = new ArrayList<>(list.size());
            for (jpa.entities.InformeSoldadura i : list) {
                merged.add(entityManager.merge(i));
            }
            list.clear();
            list.addAll(merged);
        }
    }

    public void impresion(String nombreJasper) {
        String idInforme;
        String cumple;
        cumple = jCheckBox1.isSelected()? "SI": "NO";
              
        try {
            idInforme = idInformeSoldaduraField.getText();
            String ubicacion = System.getProperty("user.dir") + "/src/reportes/" + nombreJasper;
            //llamar el repote
            Reportes reporte = new Reportes();
            reporte.informeSoldadura(logotipo,idInforme, ubicacion, jLabelRequisitoResistencia.getText(),jLabelDesviacionResistencia.getText(), cumple, jLabelPromedioCarga.getText(), jLabelPromedioResistencia.getText());
            // fin reporte
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }
    private void calcularDatos() {
        int index = masterTable.getSelectedRow();
        jpa.entities.InformeSoldadura i = list.get(masterTable.convertRowIndexToModel(index));
        Collection<jpa.entities.DetalleInforme> ds = i.getDetalleInformeList();
        if (ds != null && !ds.isEmpty()) {
            int suma = 0;
            for (DetalleInforme detalle : ds) {
                suma += detalle.getCargaMax();
            }
            double promedio = suma / ds.size();
            double promedioResistencia = (suma / ds.size()) * 9.80665002864;
            double requisito = i.getMallasIdMallas().getAreaNominal() * 241;
            if (promedioResistencia < requisito) {
                i.setCumple(false);
            } else {
                i.setCumple(true);
            }
            DecimalFormat df = new DecimalFormat("0.000");
            jLabelPromedioCarga.setText(df.format(promedio) + " Kg");
            jLabelPromedioResistencia.setText(df.format(promedioResistencia) + " N");
            jLabelRequisitoResistencia.setText(df.format(requisito) + " N");
            jLabelDesviacionResistencia.setText(df.format(promedioResistencia * 100 / requisito) + " %");
            jComboBoxMalla.setEnabled(false);
        }
    }
}
